package com.qsl.ssyx.activity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qsl.ssyx.model.activity.ActivityRule;
import com.qsl.ssyx.activity.mapper.ActivityRuleMapper;
import com.qsl.ssyx.activity.service.ActivityRuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qsl.ssyx.model.activity.CouponInfo;
import com.qsl.ssyx.model.order.CartInfo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 优惠规则 服务实现类
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-28
 */
@Service
public class ActivityRuleServiceImpl extends ServiceImpl<ActivityRuleMapper, ActivityRule> implements ActivityRuleService {

    // 根据优惠卷ID子查询activity_rule表,并根据优惠卷金额和数量分组。
    @Override
    public List<ActivityRule> getActivityRuleBy(Set<Long> activityIdSet) {
        LambdaQueryWrapper<ActivityRule> lqw = new LambdaQueryWrapper<>();
        lqw.in(ActivityRule::getActivityId, activityIdSet);  // inSql：同等于${}，存在SQL注入隐患。  in：同等于#{}，不存在SQL注入隐患。
        lqw.orderByDesc(ActivityRule::getConditionAmount, ActivityRule::getConditionNum);
        return baseMapper.selectList(lqw);
//        SELECT * FROM activity_rule
//        WHERE activity_id IN (SELECT activity_id FROM activity_sku)
//        ORDER BY
//        condition_amount DESC,
//        condition_num DESC
    }




}
